<template>
	<el-card>
		<div v-if="key == this.routePath.defaultPath">
			<!-- 搜索 -->
			<el-form :inline="true" :model="searchForm">
				<el-form-item label="表名称">
					<el-input placeholder="表名称" v-model="searchForm.tableName"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
				</el-form-item>
			</el-form>
			<!-- 列表 -->
			<!-- 列表 -->
			<el-table :data="dataList" minheight="calc(100VH - 270px)" highlight-current-row border style="width: 100%" v-loading="loading">
				<el-table-column type="selection" width="55"></el-table-column>
					<el-table-column label="序号" type="index" width="50" align="center">
						<template slot-scope="scope">
							<span>{{(searchForm.pageNum - 1) * searchForm.pageSize + scope.$index + 1}}</span>
						</template>
					</el-table-column>
					<el-table-column label="表名称" align="center" prop="tablename"   />
					<el-table-column label="表描述" align="center" prop="tablecomment"  />
					<el-table-column label="实体" align="center" prop="classname"  />
					<el-table-column label="创建时间" align="center" prop="createtime"  />
					<el-table-column label="更新时间" align="center" prop="updatetime"  />
			</el-table>
			<!-- 分页 -->
			<div v-show="!loading" class="pagination-container">
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageForm.pageNum"
				:page-sizes="pageForm.pageSizeSelect" :page-size="pageForm.pageSize" :total="pageForm.totalData" layout="total, sizes, prev, pager, next, jumper"
				:prev-text="pageForm.prevText" :next-text="pageForm.nextText">
				</el-pagination>
			</div>
		</div>
		<div v-else>
			<router-view :key="key"></router-view>
		</div>
	</el-card>
</template>
<script>
	import { findGeneratorList } from "@/api/system/generator";
	export default {
		name: "generator",
		data() {
			return {
				// 遮罩层
				loading: true,
				//路由地址
				routePath: {
					defaultPath: '/system/generator',
				},
				dataList: [],
				// 预览参数
				preview: {
					open: false,
					title: "代码预览",
					data: {},
					activeName: "domain.java"
				},
				// 搜索条件
				searchForm: {
					tableName: undefined,
					tableComment: undefined,
					pageNum: 1,
					pageSize: 10
				},
				//分页相关
				pageForm: {
					pageSizeSelect: [10, 20, 30, 50], //每页显示个数选择器的选项设置
					totalData: 0, //总条数
					pageSize: 10, //每页显示条目个数
					pageNum: 1, //当前页
					prevText: '上一页', //替代图标显示的上一页文字
					nextText: '下一页' //替代图标显示的下一页文字
				},
			};
		},
		created() {
			if (this.$route.path === this.routePath.defaultPath) {
				// 初始化获取数据列表
				this.getDateList()
			}
		},
		computed: {
			key() {
				return this.$route.path
			},
		},
		methods: {
			/** 查询表集合 */
			getDateList() {
				this.loading = true;
				findGeneratorList(this.searchForm).then(res => {
					console.log(res)
					this.dataList = res.data.responseData
					this.pageForm.totalData = parseInt(res.data.total)
				});
				this.loading = false;
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 生成代码操作 */
			handleGenTable(row) {
				const tableNames = row.tableName || this.tableNames;
				if (tableNames == "") {
					this.msgError("请选择要生成的数据");
					return;
				}
				// downLoadZip("/tool/gen/batchGenCode?tables=" + tableNames, "ruoyi");
			},
			handleSizeChange(val) {
				this.searchForm.pageSize = val
				this.getDateList()
			},
			handleCurrentChange(val) {
				this.searchForm.pageNum = val
				this.getDateList()
			},
			handleSearch() {
				this.getDateList();
			},
		}
	};
</script>
